package com.example.weathertemplate.controller;

import com.example.commonsinterface.dto.WeatherResponse;
import com.example.weathertemplate.service.RedisCache;
import com.example.weathertemplate.service.SearchCity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping
public class WeatherController {


    @Autowired
    private RedisCache redisCache;

    @Autowired
    private SearchCity searchCity;

    @RequestMapping("/search") //http://localhost:9060/search?cityid=101270101
    @ResponseBody
    public ModelAndView search(String cityid) {
        System.out.println(cityid);
        ModelAndView mav = new ModelAndView("weather");
        WeatherResponse result = redisCache.searchWeather(cityid);

        System.out.println(result.toString());
        mav.addObject("weatherResponse", result);
        mav.addObject("cityList", searchCity.searchCity());
        mav.addObject("cityid", cityid);
        return mav;
    }

}
